********************************
***Perception Anti-Immigrant***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
global draftout "../../Draft/Figures/"
} 

use 3_clean_data, replace

*********************************
***Create Variables and Format***
*********************************

/*Order or Treatment Groups*
5 7 6 8 1 3 2 4 9 10
*/

replace dummy_source_obama=dummy_source_obama*100
replace dummy_source_trump=dummy_source_trump*100
replace dummy_source_dem=dummy_source_dem*100
replace dummy_source_rep=dummy_source_rep*100

gen prob_sourcecorrect=dummy_source_obama if (treat==2 | treat==4 | treat==6 | treat==8 | treat==10)
replace prob_sourcecorrect=dummy_source_trump if (treat==1 | treat==3 | treat==5 | treat==7 | treat==9)

gen prob_partycorrect=dummy_source_dem if (treat==2 | treat==4 | treat==6 | treat==8 | treat==10)
replace prob_partycorrect=dummy_source_rep if (treat==1 | treat==3 | treat==5 | treat==7 | treat==9)

gen prob_strength=prob_content_anti if treat>4 & treat<9
replace prob_strength=prob_content_pro if treat<5 & treat!=0

foreach y in 5 7 6 8 1 3 2 4 9 10 {
	gen t`y'=treatment==`y'
	}

global source5 	"Trump"
global source7 	"Actor, Trump"
global source6 	"Obama"
global source8 	"Actor, Obama"
global source1 	"Trump"
global source3 	"Actor, Trump"
global source2 	"Obama"
global source4 	"Actor, Obama"
global source9 	"Trump"
global source10 "Obama"
global message5 "Anti-Immigrant"
global message7 "Anti-Immigrant"
global message6 "Anti-Immigrant"
global message8 "Anti-Immigrant"
global message1 "Pro-Immigrant"
global message3 "Pro-Immigrant"
global message2 "Pro-Immigrant"
global message4 "Pro-Immigrant"
global message9 "Turkey"
global message10 "Turkey"
 
foreach y in 5 6 1 2 9 {
	global space`y' "[.2em]" 
	} 
foreach y in 8 4 10 {
	global space`y' "[1em]" 
	} 

*****************************
*****************************
*****************************
****************************************
****Bar Graphs of Perception Results****
****************************************

*Perception Anti*

*order bars the way you want them.
gen ta=1 if treat==5 & recruit==0
replace ta=2 if treat==6 & recruit==0
replace ta=3 if treat==7 & recruit==0
replace ta=4 if treat==8 & recruit==0
replace ta=5 if treat==5 & recruit==1
replace ta=6 if treat==6 & recruit==1
replace ta=7 if treat==7 & recruit==1
replace ta=8 if treat==8 & recruit==1

label define ta 1 `" "Anti" "Trump" "' 2 `" "Anti" "Obama" "' ///
	3 `" "Anti" "Trump" "(Actor)" "' 4 `" "Anti" "Obama" "(Actor)"  "' /// 
	5 `" "Anti" "Trump" "' 6 `" "Anti" "Obama" "' ///
	7 `" "Anti" "Trump" "(Actor)" "' 8 `" "Anti" "Obama" "(Actor)"  "', replace 

label values ta ta

bysort ta: egen pa=mean(prob_strength)
bysort ta: gen n=_n==1 if pa!=.

gen pa2=round(pa*10)/10
format pa2 %6.1f

# delimit ;

twoway 
	(bar pa ta if n==1 & recruit==0 & ta<=2, color(black) barwidth(0.7))
	(bar pa ta if n==1 & recruit==0 & ta<=4 & ta>=3, color(white) lcolor(black) barwidth(0.7))
	(bar pa ta if n==1 & recruit==1 & ta<=6 & ta>=5, color(black) barwidth(0.7))
	(bar pa ta if n==1 & recruit==1 & ta<=8 & ta>=7, color(white) lcolor(black) barwidth(0.7))
	(scatter pa2 ta if n==1, msym(none) mlab(pa2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Perception Anti-Immigrant" " ")
	xtitle(" " " " " " "{bf:Republicans}						{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/A1_Perception_Anti.eps", replace	

drop n

*Perception Pro*

*order bars the way you want them.
gen tp=1 if treat==1 & recruit==0
replace tp=2 if treat==2 & recruit==0
replace tp=3 if treat==3 & recruit==0
replace tp=4 if treat==4 & recruit==0
replace tp=5 if treat==1 & recruit==1
replace tp=6 if treat==2 & recruit==1
replace tp=7 if treat==3 & recruit==1
replace tp=8 if treat==4 & recruit==1

label define tp 1 `" "Pro" "Trump" "' 2 `" "Pro" "Obama" "' ///
	3 `" "Pro" "Trump" "(Actor)" "' 4 `" "Pro" "Obama" "(Actor)" "' /// 
	5 `" "Pro" "Trump" "' 6 `" "Pro" "Obama" "' ///
	7 `" "Pro" "Trump"  "(Actor)" "' 8 `" "Pro" "Obama" "(Actor)" "', replace  

label values tp tp

bysort tp: egen pp=mean(prob_strength)
bysort tp: gen n=_n==1 if pp!=.

gen pp2=round(pp*10)/10
format pp2 %6.1f

# delimit ;

twoway 
	(bar pp tp if n==1 & recruit==0 & tp<=2, color(black) barwidth(0.7))
	(bar pp tp if n==1 & recruit==0 & tp<=4 & tp>=3, color(white) lcolor(black) barwidth(0.7))
	(bar pp tp if n==1 & recruit==1 & tp<=6 & tp>=5, color(black) barwidth(0.7))
	(bar pp tp if n==1 & recruit==1 & tp<=8 & tp>=7, color(white) lcolor(black) barwidth(0.7))
	(scatter pp2 tp if n==1, msym(none) mlab(pp2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Perception Pro-Immigrant" " ")
	xtitle(" " " " " " "{bf:Republicans}						{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/A1_Perception_Pro.eps", replace	

drop n

*Perception Correct President*
*President Treatments*
gen tc=.
replace tc=1 if treat==1 & recruit==0
replace tc=2 if treat==2 & recruit==0
replace tc=3 if treat==5 & recruit==0
replace tc=4 if treat==6 & recruit==0
replace tc=5 if treat==9 & recruit==0
replace tc=6 if treat==10 & recruit==0
replace tc=7 if treat==1 & recruit==1
replace tc=8 if treat==2 & recruit==1
replace tc=9 if treat==5 & recruit==1
replace tc=10 if treat==6 & recruit==1
replace tc=11 if treat==9 & recruit==1
replace tc=12 if treat==10 & recruit==1

label define tc 1 `" "Anti" "Trump" "' 2 `" "Anti" "Obama" "' ///
	3 `" "Pro" "Trump" "' 4 `" "Pro" "Obama" "' /// 
	5 `" "Turkey" "Trump" "' 6 `" "Turkey" "Obama" "' ///
	7 `" "Anti" "Trump" "' 8 `" "Anti" "Obama" "' ///
	9 `"  "Pro" "Trump""' 10 `" "Pro" "Obama"  "' /// 
	11 `" "Turkey" "Trump" "' 12 `" "Turkey" "Obama" "', replace 
	
label values tc tc

bysort tc: egen pc=mean(prob_sourcecorrect)
bysort tc: gen n=_n==1 if pc!=.	

gen pc2=round(pc*10)/10
format pc2 %6.1f

# delimit ;

twoway 
	(bar pc tc if n==1 & recruit==0 & tc<=6, color(black) barwidth(0.7))
	(bar pc tc if n==1 & recruit==1 & tc<=12 & tc>=7, color(black) barwidth(0.7))
	(scatter pc2 tc if n==1, msym(none) mlab(pc2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)12, valuelabel)
	xline(6.5, lcolor(black) lpattern(dash))
	ytitle("Perception Correct President" " ")
	xtitle(" " " " "{bf:Republicans}							{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/A1_Perception_CorrectSource_President.eps", replace	

drop n tc pc pc2 

*Perception Correct President*
*Actor Treatments*
gen tc=1 if treat==7 & recruit==0
replace tc=2 if treat==8 & recruit==0
replace tc=3 if treat==3 & recruit==0
replace tc=4 if treat==4 & recruit==0
replace tc=5 if treat==7 & recruit==1
replace tc=6 if treat==8 & recruit==1
replace tc=7 if treat==3 & recruit==1
replace tc=8 if treat==4 & recruit==1

label define tc 1 `" "Anti" "Trump" "(Actor)" "' 2 `" "Anti" "Obama" "(Actor)" "' ///
	3 `" "Pro" "Trump" "(Actor)" "' 4 `" "Pro" "Obama"  "(Actor)" "' /// 
	5 `" "Anti" "Trump" "(Actor)" "' 6 `" "Anti" "Obama" "(Actor)" "' ///
	7 `" "Pro" "Trump"  "(Actor)" "' 8 `" "Pro" "Obama" "(Actor)" "', replace 	
label values tc tc

bysort tc: egen pc=mean(prob_sourcecorrect)
bysort tc: gen n=_n==1 if pc!=.	

gen pc2=round(pc*10)/10
format pc2 %6.1f

# delimit ;

twoway 
	(bar pc tc if n==1 & recruit==0 & tc<=4, color(white) lcolor(black) barwidth(0.7))
	(bar pc tc if n==1 & recruit==1 & tc<=8 & tc>=4, color(white) lcolor(black) barwidth(0.7))
	(scatter pc2 tc if n==1, msym(none) mlab(pc2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Perception Correct President" " ")
	xtitle(" " " " " " "{bf:Republicans}						{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/A1_Perception_CorrectSource_Actor.eps", replace	

drop n tc


****************************************
****Bar Graphs of Content Similarity****
****************************************

*Perception Anti/Pro*

*order bars the way you want them.
gen td=1 if treat==7 & recruit==0
replace td=2 if treat==8 & recruit==0
replace td=3 if treat==3 & recruit==0
replace td=4 if treat==4 & recruit==0
replace td=5 if treat==7 & recruit==1
replace td=6 if treat==8 & recruit==1
replace td=7 if treat==3 & recruit==1
replace td=8 if treat==4 & recruit==1

label define td 1 `" "Anti" "Trump" "(Actor)" "' 2 `" "Anti" "Obama" "(Actor)" "' ///
	3 `" "Pro" "Trump" "(Actor)" "' 4 `" "Pro" "Obama"  "(Actor)" "' /// 
	5 `" "Anti" "Trump" "(Actor)" "' 6 `" "Anti" "Obama" "(Actor)" "' ///
	7 `" "Pro" "Trump"  "(Actor)" "' 8 `" "Pro" "Obama" "(Actor)" "', replace 	


label values td td

bysort td: egen pd=mean(prob_strength)
bysort td: gen n=_n==1 if pd!=.

gen pd2=round(pd*10)/10
format pd2 %6.1f

# delimit ;

twoway 
	(bar pd td if n==1 & recruit==0 & td<=2, color(black) barwidth(0.7))
	(bar pd td if n==1 & recruit==0 & td<=4 & td>=3, color(white) lcolor(black) barwidth(0.7))
	(bar pd td if n==1 & recruit==1 & td<=6 & td>=5, color(white) lcolor(black) barwidth(0.7))
	(bar pd td if n==1 & recruit==1 & td<=8 & td>=7, color(black) barwidth(0.7))
	(scatter pd2 td if n==1, msym(none) mlab(pd2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Strength of Message" " ")
	xtitle(" " " " " " "{bf:Republicans}						{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/3_Perception_SimilarContent.eps", replace	

*****************************************************
*Bar Graphs of Trust vs. Surprise*
*****************************************************

*Trust*
//Fan of Trump
//Fan of Obama
//Voted for Trump

*order bars the way you want them.
sort recruit
gen tt=1 if _n==1 & recruit==0
replace tt=2 if _n==2 & recruit==0
replace tt=3 if _n==3 & recruit==0
gsort -recruit
replace tt=4 if _n==1 & recruit==1
replace tt=5 if _n==2 & recruit==1
replace tt=6 if _n==3 & recruit==1


label define tt 1 `" "Trump" "Voter" "(2016)" "' 2 `" "Trump" "Fan" "' ///
	3 `" "Obama" "Fan" "' 4 `" "Trump" "Voter" "(2016)" "' /// 
	5 `" "Trump" "Fan" "' 6 `" "Obama" "Fan" "' , replace 
	
label values tt tt

gen pt=.
sum trump2016 if recruit==0
replace pt=r(mean) if tt==1
sum trump2016 if recruit==1
replace pt=r(mean) if tt==4

sum trumpfan if recruit==0
replace pt=r(mean) if tt==2
sum trumpfan if recruit==1
replace pt=r(mean) if tt==5

sum obamafan if recruit==0
replace pt=r(mean) if tt==3
sum obamafan if recruit==1
replace pt=r(mean) if tt==6

replace pt=pt*100
gen pt2=round(pt*10)/10
format pt2 %6.1f

# delimit ;

twoway 
	(bar pt tt if tt==1, color(black) barwidth(0.7))
	(bar pt tt if tt==2 | tt==3, color(white) lcolor(black) barwidth(0.7))
	(bar pt tt if tt==4, color(black) barwidth(0.7))
	(bar pt tt if tt==5 | tt==6, color(white) lcolor(black) barwidth(0.7))
	(scatter pt tt if tt<7, msym(none) mlab(pt2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)6, valuelabel)
	xline(3.5, lcolor(black) lpattern(dash))
	ytitle("Measures of Trust in Presidents" " ")
	xtitle(" " " " " " "{bf:Republicans}		  						{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/3_TrustMeasures.eps", replace	


*Surprise*

*Perception Incorrect President*
*Actor Treatments*
gen ts=1 if treat==7 & recruit==0
replace ts=2 if treat==8 & recruit==0
replace ts=3 if treat==3 & recruit==0
replace ts=4 if treat==4 & recruit==0
replace ts=5 if treat==7 & recruit==1
replace ts=6 if treat==8 & recruit==1
replace ts=7 if treat==3 & recruit==1
replace ts=8 if treat==4 & recruit==1

label define ts 1 `" "Anti" "Trump" "(Actor)" "' 2 `" "Anti" "Obama" "(Actor)" "' ///
	3 `" "Pro" "Trump" "(Actor)" "' 4 `" "Pro" "Obama"  "(Actor)" "' /// 
	5 `" "Anti" "Trump" "(Actor)" "' 6 `" "Anti" "Obama" "(Actor)" "' ///
	7 `" "Pro" "Trump"  "(Actor)" "' 8 `" "Pro" "Obama" "(Actor)" "', replace 	
	
label values ts ts

gen ps=100-pc
gen ps2=round(ps*10)/10
format ps2 %6.1f

# delimit ;

twoway 
	(bar ps ts if n==1 & recruit==0 & (ts==1 | ts==4), color(black) barwidth(0.7))
	(bar ps ts if n==1 & recruit==0 & (ts==2 | ts==3), color(white) lcolor(black) barwidth(0.7))
	(bar ps ts if n==1 & recruit==1 & (ts==5 | ts==8), color(black) barwidth(0.7))
	(bar ps ts if n==1 & recruit==1 & (ts==6 | ts==7), color(white) lcolor(black) barwidth(0.7))
	(scatter ps2 ts if n==1, msym(none) mlab(ps2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Measure of Message Surprise" " ")
	xtitle(" " " " " " "{bf:Republicans}					    		{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/3_SurpriseMeasures.eps", replace	


*Party Version
*Perception Incorrect President*
*Actor Treatments*

*Party version
*Actor Treatments*
gen tc=1 if treat==7 & recruit==0
replace tc=2 if treat==8 & recruit==0
replace tc=3 if treat==3 & recruit==0
replace tc=4 if treat==4 & recruit==0
replace tc=5 if treat==7 & recruit==1
replace tc=6 if treat==8 & recruit==1
replace tc=7 if treat==3 & recruit==1
replace tc=8 if treat==4 & recruit==1

label define tc 1 `" "Anti" "Trump" "(Actor)" "' 2 `" "Anti" "Obama" "(Actor)" "' ///
	3 `" "Pro" "Trump" "(Actor)" "' 4 `" "Pro" "Obama"  "(Actor)" "' /// 
	5 `" "Anti" "Trump" "(Actor)" "' 6 `" "Anti" "Obama" "(Actor)" "' ///
	7 `" "Pro" "Trump"  "(Actor)" "' 8 `" "Pro" "Obama" "(Actor)" "', replace 	
label values tc tc

drop n
bysort tc: egen pcx=mean(prob_partycorrect)
bysort tc: gen n=_n==1 if pcx!=.	

gen pcx2=round(pcx*10)/10
format pcx2 %6.1f

gen psx=100-pcx
gen psx2=round(psx*10)/10
format psx2 %6.1f

# delimit ;

twoway 
	(bar psx ts if n==1 & recruit==0 & (ts==1 | ts==4), color(black) barwidth(0.7))
	(bar psx ts if n==1 & recruit==0 & (ts==2 | ts==3), color(white) lcolor(black) barwidth(0.7))
	(bar psx ts if n==1 & recruit==1 & (ts==5 | ts==8), color(black) barwidth(0.7))
	(bar psx ts if n==1 & recruit==1 & (ts==6 | ts==7), color(white) lcolor(black) barwidth(0.7))
	(scatter psx2 ts if n==1, msym(none) mlab(psx2) mlabpos(12) mlabcolor(black))
	, 
	graphregion(color(white)) 
	ylabel(0(10)105, grid) ytick(0(10)100)
	xlabel(1(1)8, valuelabel)
	xline(4.5, lcolor(black) lpattern(dash))
	ytitle("Measure of Message Surprise (Party)" " ")
	xtitle(" " " " " " "{bf:Republicans}					    		{bf:Democrats}")
	legend(off) ylabel(, nogrid)
	xsize(7) ysize(4) 
	;
	
# delimit cr

graph export "$draftout/A2_SurpriseMeasures_Party.eps", replace	
